const net = require('node:net')
const HOST = '127.0.0.1'
const PORT = 6969

// 创建一个TCP服务器实例，调用listen函数开始监听指定端口
// 传入
net.createServer((socket) => {
	console.log(`connected ${socket.remoteAddress} ${socket.remotePort}`)
	socket.on('data', (buf) => {
		console.log(`server data ${socket.remoteAddress}:${buf}`)
		socket.write(`You said “${buf}”`)
	})
	socket.on('close', (data) => {
		console.log(`server closed ${socket.remoteAddress} ${HOST}:${PORT}`)
		console.log(data)
	})
}).listen(PORT, HOST, () => {
	console.log(`Server listening on ${HOST}:${PORT}`)
})